﻿using System;

class MaximalSumSequence
{
    static void Main()
    {
        int[] array = { 45, 5, -67, -1, 0, 34, 3, -17, 55, -1, 10, -145, 12 };
        int maxSum = 0;
        int length = 0;
        int index = 0;
        int tempSum = 0;
        
        for (int i = 0; i < array.Length; i++)
        {
            tempSum = 0;

            for (int k = i; k < array.Length; k++)
            {
                tempSum += array[k];

                if (tempSum > maxSum)
                {
                    maxSum = tempSum;
                    index = i;
                    length = k - i;
                }
            }
        }

        Console.WriteLine("The elements of the maximal sum are:");

        for (int i = index; i <= index + length; i++)
        {
            Console.WriteLine(array[i]);
        }

        Console.WriteLine("The maximal sum is: " + maxSum);
    }
}